package Statistics;

import java.util.ArrayList;

import Definitions.GraphClass;
import Definitions.NodeClass;
import Global.DirectoryStructureAndSettingsClass;

public class homophilyCalculatorClass 
{
	GraphClass currentGraph;
	DegreeStatistics currentDegreeStatistics;
	double homophilyOfTheGraph;
	int edgeType;
	int lastCalculationIsForNeighbourhoodLevel;

	public homophilyCalculatorClass(GraphClass graph, int edgeType, DegreeStatistics currentDegreeStatistics)
	{
		currentGraph = graph;
		homophilyOfTheGraph = 0;
		this.edgeType = edgeType;
		this.currentDegreeStatistics = currentDegreeStatistics;		
	}
	
	double calculateHomophilyOfTheGraph(int neighbourhoodLevel)
	{
		ArrayList <NodeClass> dataSetOfTheGraph = currentGraph.getDataSet();
		int sizeOfTheGraph = dataSetOfTheGraph.size();
		double[] homophilyListOfTheNodes = new double[sizeOfTheGraph];
		double homophilyOfTheNode;
		
		homophilyOfTheGraph = 0;
		lastCalculationIsForNeighbourhoodLevel = neighbourhoodLevel;
		
		System.out.println("Number of nodes: "+ dataSetOfTheGraph.size());
				
		for(int i=0; i<dataSetOfTheGraph.size(); i++)
   	  	{
			homophilyOfTheNode = dataSetOfTheGraph.get(i).getHomophilyOfTheNode(edgeType, neighbourhoodLevel);
			homophilyListOfTheNodes[i] = homophilyOfTheNode; 
			//System.out.println("i:"+i+" homophilyOfTheGraph: "+ homophilyOfTheGraph);
			homophilyOfTheGraph += homophilyOfTheNode;
   		}
		
		homophilyOfTheGraph = (double)homophilyOfTheGraph / dataSetOfTheGraph.size();
		if(neighbourhoodLevel==1)
			currentGraph.getPropertiesOfTheGraphWithRespectToEdgeType().get(edgeType).homophilyRelatedProps.setHomophilyRelatedParameters(homophilyListOfTheNodes, homophilyOfTheGraph);
		return homophilyOfTheGraph;		
	}	
	
	void print()
	{
		System.out.println("homophilyOfTheGraph("+lastCalculationIsForNeighbourhoodLevel+"): "+ homophilyOfTheGraph);
		DirectoryStructureAndSettingsClass.addToLog("homophilyOfTheGraph("+lastCalculationIsForNeighbourhoodLevel+"): "+ homophilyOfTheGraph);
	}
}
